INDIA : +91 7702055576 USA : +1 508-986-9109

AWS CloudWatch

AWS CloudWatch allows you to set up alarms to monitor metrics and send notifications when certain thresholds are met. You can integrate CloudWatch alarms with a webhook to receive notifications in an external system such as a chat application or an incident management system.

To set up a webhook integration for CloudWatch alarms, follow these steps:

  1. Create a webhook in your external system that can receive the CloudWatch alarm notifications. The webhook should be able to parse and process the payload sent by CloudWatch. Make sure to take note of the webhook URL.
  2. In the AWS Management Console, navigate to the CloudWatch service and select “Alarms” from the left-hand menu.
  3. Create a new alarm or select an existing alarm that you want to integrate with the webhook.
  4. Click on the “Actions” dropdown and select “Add notification”.
  5. Select “Lambda function” as the notification target.
  6. Click on the “Configure details” button and enter a name and description for the notification target.
  7. In the “Lambda function” section, select “Create a new Lambda function” and enter a name and description for the function.
  8. Choose a runtime for the function and select “Create a new role with basic Lambda permissions” as the execution role.
  9. Under the “Function code” section, select “Edit code inline”.
  10. Paste the following code into the editor, replacing the webhook URL with the URL of your webhook:

var https = require(‘https’);

exports.handler = function(event, context) {

  console.log(‘Received CloudWatch notification:’, JSON.stringify(event, null, 2));

  var postData = JSON.stringify(event);

  var options = {

    hostname: ‘your-webhook-url.com’,

    port: 443,

    path: ‘/webhook-endpoint’,

    method: ‘POST’,

    headers: {

      ‘Content-Type’: ‘application/json’,

      ‘Content-Length’: postData.length

    }

  };

  var req = https.request(options, function(res) {

    console.log(‘Webhook response status code:’, res.statusCode);

    context.succeed();

  });

  req.on(‘error’, function(e) {

    console.log(‘Error sending webhook:’, e);

    context.fail();

  });

  req.write(postData);

  req.end();

};

  1. Click on the “Save” button to save the function code.
  2. Click on the “Create function” button to create the function and associate it with the CloudWatch alarm.

Once the integration is set up, CloudWatch will send notifications to the Lambda function whenever the alarm threshold is met. The Lambda function will then forward the notification payload to the webhook URL you specified, allowing you to receive notifications in your external system.

Registration Procedure:

  1. Open AWS console and search for sns (simple notification service)
simple notification service

2. Under topics click on Create Topic

Amozon SNS

3. Select Standard Topic type and give the unique topic name and display name and submit the topic by giving proper permissions

Standard

4. In view topic page click on “create subscription”

create subscription

5. Copy the integration url and paste at create subscription by choosing the https protocol

create subscription details

6. To configure the above topic to send notification when aws cloudwatch alarms meet the threshold, please go to the alarms section in aws cloudwatch

use the default delivery policy

7. Click on any existing alarm, under actions click on Edit

maximum delay retries - 0

8. Update the metrics and conditions and click on Next

request confirmation

9. Under configure actions, select an existing SNS topic and choose the created topic at SNS and click on Update Alarm 

show recent payload - AWS CloudWatch
the file does not appear to have any style information

10. To configure the above topic to send notification when aws cloudwatch alarms meet the threshold, please go to the alarms section in aws cloudwatch

alarms(2)

11. Click on any existing alarm, under actions click on Edit

select edit from the actions dropdown menu

12. Update the metrics and conditions and click on Next

13. Under configure actions, select an existing SNS topic and choose the created topic at SNS and click on Update Alarm 

configure actions
arrow